﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    initState();

    SDL_Init(SDL_INIT_VIDEO);

    WORD version;
    WSADATA wsaData;
    version = MAKEWORD(2, 2);
    WSAStartup(version, &wsaData);
}

MainWindow::~MainWindow()
{
    SDL_Quit();
    WSACleanup();

    delete ui;
}

void MainWindow::initState()
{
    this->setWindowTitle("LibRTMP 文件推流");

    void *handle = (void *)ui->widgetShow->winId();
    mediaCapture.videoOutput->setShowHandle(handle);
}

void MainWindow::on_btnSelect_clicked()
{
    filePath = QFileDialog::getOpenFileName(this, "推流文件", ".", "*.*");
    ui->lineEdit->setText(filePath);
}

void MainWindow::on_btnStartPush_clicked()
{
    if(filePath.isEmpty())
        return;

    mediaCapture.filePath = filePath;
    mediaCapture.setRunState(true);
}

void MainWindow::on_btnStopPush_clicked()
{
    mediaCapture.setRunState(false);
}
